package com.dingdayu.club.admin.adapter;

/**
 * Created by 大小姐 on 2015/10/24.
 */
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingdayu.club.admin.R;
import com.dingdayu.club.admin.common.util.ImageLoader;

import org.kymjs.kjframe.KJBitmap;

public class MemberAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; //用来下载图片的类，后面有介绍

    public MemberAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_item_member, null);

        TextView title = (TextView)vi.findViewById(R.id.title); // 标题
        TextView artist = (TextView)vi.findViewById(R.id.artist); // 歌手名
        TextView duration = (TextView)vi.findViewById(R.id.duration); // 时长
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // 缩略图

        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);

        // 设置ListView的相关值
        title.setText(song.get("name"));
        artist.setText(song.get("college") + " - " + song.get("major"));
        if("0.00".equals(song.get("cost"))){
            duration.setText("暂未审核");

        }else {
            duration.setText("正式成员");
        }


        if(song.get("image") != "") {
            KJBitmap kjb = new KJBitmap();
            Log.i("Main", song.get("image"));
            kjb.display(thumb_image, song.get("image") + "?imageView2/1/w/150/h/150");
        }else{
            thumb_image.setImageResource(R.drawable.ic_launcher);
        }
        return vi;
        }
}